﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Drawing.Imaging;
using Editor.Custom_Controls;
using Editor.Utilities;

namespace Editor.PageControls
{
    public class PageImageBox : PageControl<byte[]>, IDictSubject<byte[]>
    {
        public PageImageBox()
        {
            Dictionary = new SDictionary<byte[]>();
        }

        public bool IsLong { get; set; }
        public bool IsFormula { get; set; }
        public Size ScrollableSize { get; set; }
        public int ScrollSize { get; set; }

        [XmlIgnore]
        public Image CurrentImage 
        {
            get
            {
                return ImageWorker.GetImage(CurrentElement);
            }
            set
            {
                CurrentElement = ImageWorker.GetByteArray(value);
            }
        }

        public override string NamingPrefix
        {
            get { return "resim"; }
        }

        public override void UpdateInnerControl()
        {
            ScrollableImagePanel imagePanel = InnerControl as ScrollableImagePanel;

            imagePanel.Location = Location;
            imagePanel.Visible = Visible;
            imagePanel.Picture = CurrentImage;
            imagePanel.Size = Size;
            imagePanel.IsScrollable = IsLong;
            imagePanel.ScrollableSize = ScrollableSize;
            imagePanel.ScrollSize = ScrollSize;
        }

        protected override PropertiesFormBase generatePropertiesForm()
        {
            return new ImageBoxProperties();
        }

        protected override Control generateInnerControl()
        {
            return new ScrollableImagePanel();
        }

        public override object Clone()
        {
            PageImageBox newPageImageBox = new PageImageBox();

            newPageImageBox.Location = Location;
            newPageImageBox.Size = Size;
            newPageImageBox.Name = Name;
            newPageImageBox.Visible = Visible;
            newPageImageBox.IsLong = IsLong;
            newPageImageBox.IsFormula = IsFormula;
            newPageImageBox.ScrollableSize = ScrollableSize;
            newPageImageBox.Dictionary = Dictionary.Clone() as SDictionary<byte[]>;

            return newPageImageBox;
        }
    }
}
